home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
c
/
du_lib
/
resource.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-10
|
15KB
|
497 lines
/*
DU_LIB v2
Gem Window Management & Dialog Library For Lattice C
½1994,95, by Craig Graham.
Based on the DU_LIBv1 Library for HiSoft Basic.
*/
#include <FCNTL.H>
#include <STDIO.H>
#include <OSBIND.H>
#include "DULIB.H"
/*
RESOURCE FILE HANDLER
*/
/* Convert a colour drawn form into a mono form */
void rsrc_form2mono(short d, short b)
{
OBJECT *a;
OBJECT *o;
TEDINFO *t;
short obn,bgc,cw;
unsigned long c;
ICONBLK *ico;
bgc=b<<4;
rsrc_gaddr(0,d,&a);
obn=0;
do {
o=a+obn;
switch (o->ob_type)
{
case G_BOXCHAR:
t=(TEDINFO*)o->ob_spec;
c=(unsigned long)o->ob_spec;
cw=(short)c&65535;
c=(unsigned long)(c&(unsigned long)(4294967295-65535)); // Preserve the character & border info.
if ((cw&15)==0)
{
cw=cw&((15<<12)+(1<<7)+(7<<4)); // Mask out text colour & set fill colour to 0
cw=cw+bgc+1;
}else{
cw=cw&((15<<12)+(1<<7)+(7<<4)); // Mask out text colour & set fill colour to 0
}
cw=cw+(1<<8); // Text colour to black
o->ob_spec=(void*)(c+cw);
/* Using 3d effects to highlight things is turned off for mono */
if (o->ob_flags & mask_indicator) o->ob_flags=o->ob_flags - mask_indicator;
if (o->ob_flags & mask_activator) o->ob_flags=o->ob_flags - mask_activator;
break;
case G_TEXT:
t=(TEDINFO*)o->ob_spec;
cw=t->te_color;
cw=cw&((15<<12)+(1<<7)+(7<<4)); // Mask out text colour & set fill colour to 0
cw=cw+(1<<8); // Text colour to black
t->te_color=cw;
/* Using 3d effects to highlight things is turned off for mono */
if (o->ob_flags & mask_indicator) o->ob_flags=o->ob_flags - mask_indicator;
if (o->ob_flags & mask_activator) o->ob_flags=o->ob_flags - mask_activator;
break;
case G_BOXTEXT:
t=(TEDINFO*)o->ob_spec;
cw=t->te_color;
if ((cw&15)==0)
{
cw=cw&((15<<12)+(1<<7)+(7<<4)); // Mask out text colour & set fill colour to 0
cw=cw+bgc+1;
} else {
cw=cw&((15<<12)+(1<<7)+(7<<4)); // Mask out text colour & set fill colour to 0
}
cw=cw+(1<<8); // Text colour to black
t->te_color=cw;
/* Using 3d effects to highlight things is turned off for mono */
if (o->ob_flags & mask_indicator) o->ob_flags=o->ob_flags - mask_indicator;
if (o->ob_flags & mask_activator) o->ob_flags=o->ob_flags - mask_activator;
break;
case G_FTEXT:
t=(TEDINFO*)o->ob_spec;
cw=t->te_color;
cw=cw&((15<<12)+(1<<7)+(7<<4)); // Mask out text colour & set fill colour to 0
cw=cw+(1<<8); // Text colour to black
t->te_color=cw;
/* Using 3d effects to highlight things is turned off for mono */
if (o->ob_flags & mask_indicator) o->ob_flags=o->ob_flags - mask_indicator;
if (o->ob_flags & mask_activator) o->ob_flags=o->ob_flags - mask_activator;
break;
case G_FBOXTEXT:
t=(TEDINFO*)o->ob_spec;
cw=t->te_color;
if ((cw&15)==0)
{
cw=cw&((15<<12)+(1<<7)+(7<<4)); // Mask out text colour & set fill colour to 0
cw=cw+bgc+1;
} else {
cw=cw&((15<<12)+(1<<7)+(7<<4)); // Mask out text colour & set fill colour to 0
}
cw=cw+(1<<8); // Text colour to black
t->te_color=cw;
/* Using 3d effects to highlight things is turned off for mono */
if (o->ob_flags & mask_indicator) o->ob_flags=o->ob_flags - mask_indicator;
if (o->ob_flags & mask_activator) o->ob_flags=o->ob_flags - mask_activator;
break;
case G_BOX:
c=(unsigned long)o->ob_spec;
if ((c&240) != 0)
{
if (((c&15)==8)||(o->ob_flags & (mask_indicator|mask_activator) !=0))
{
c=(c & !255) & !(61440);
if ((o->ob_flags & (mask_indicator|mask_activator))==0) /* Using 3d effects to highlight things is turned off for mono */
{
c=c | (bgc + 7 + 65536 + 4096);
}else{
c=c | (7 + 65536 + 4096);
}
o->ob_spec=(void *)c;
}
} else {
o->ob_state=o->ob_state|OUTLINED;
}
/* Using 3d effects to highlight things is turned off for mono */
o->ob_flags&=~(mask_indicator|mask_activator);
break;
case G_ICON:
ico=(ICONBLK*)o->ob_spec;
ico->ib_char=4161;
o->ob_flags&=~(mask_indicator|mask_activator);
o->ob_state=o->ob_state|OUTLINED;
break;
case G_CICON:
o->ob_type=G_ICON; /* Make the colour icon into a standard mono icon so the old AES can handle it */
ico=(ICONBLK*)o->ob_spec;
ico->ib_char=4161;
o->ob_flags&=~(mask_indicator|mask_activator);
o->ob_state=o->ob_state | OUTLINED;
break;
}
obn++;
} while (((o->ob_flags) & LASTOB)!=LASTOB);
}
/*
Simulate the standard GEM AES resource access functions.
I've added these to Steve's routines to act as a bit of an interface
to his routines.
*/
void *GEM_RESOURCE=NULL; /* The address of the single 'GEM' resource file */
/* Resource char to pixel coord conversion constants.
If you are designing your resources in ST-Low res, change DU_RSY_CONV to 8 */
#define DU_RSX_CONV 8
#define DU_RSY_CONV 16
int DUrsrc_load(char *n)
{
GEM_RESOURCE=LoadResources(n, DU_RSX_CONV, DU_RSY_CONV);
if (GEM_RESOURCE)
return 1;
else
return 0;
}
int DUrsrc_free(void)
{
if (GEM_RESOURCE)
{
FreeResources(GEM_RESOURCE);
return 1;
}
return 0;
}
/*
Replacement for rsrc_gaddr
If you only ever use the find tree mode (R_TREE) of rsrc_gaddr,
then define RSRC_GADDR_ONLY_TREES to get a slightly faster response.
*/
int DUrsrc_gaddr(int type, int index, void *addr)
{
OBJECT **tree_addr;
#ifndef RSRC_GADDR_ONLY_TREES
char **text_addr;
void **image_addr;
switch(type)
{
case R_TREE:
tree_addr=(OBJECT**)addr;
*tree_addr=ResourceTree(GEM_RESOURCE,index);
break;
case R_STRING:
text_addr=(char**)addr;
*text_addr=ResourceString(GEM_RESOURCE,index);
break;
case R_IMAGEDATA:
image_addr=(void**)addr;
*image_addr=ResourceImage(GEM_RESOURCE,index);
break;
}
#else
tree_addr=(OBJECT**)addr;
*tree_addr=ResourceTree(GEM_RESOURCE,index);
#endif
return 1;
}
/*
Code in this module is based on the resource loader from
Steve Sowerby's AGiLE library. Thanks to Steve for allowing
me to use his code.
*/
short resWidth,resHeight;
/*
FixColourIconData : Convert a colour icon from device independent to device specific
*/
void FixColourIconData(CICONBLK *icon)
{
CICON *c;
MFDB src,dst;
for(c=icon->mainlist; c; c=c->next_res)
{
src.fd_w = icon->monoblk.ib_wicon; /*Transform standard icon*/
src.fd_h = icon->monoblk.ib_hicon;
src.fd_wdwidth = icon->monoblk.ib_wicon>>4;
src.fd_stand = 1;
src.fd_r1 = src.fd_r2 = src.fd_r3 = 0;
src.fd_nplanes = c->num_planes;
src.fd_addr = c->col_data;
dst = src;
dst.fd_stand = 0;
vr_trnfm(x_handle,&src,&dst);
if (c->sel_data) /*Transform selected icon if exists*/
{
src.fd_w = icon->monoblk.ib_wicon;
src.fd_h = icon->monoblk.ib_hicon;
src.fd_wdwidth = icon->monoblk.ib_wicon>>4;
src.fd_stand = 1;
src.fd_r1 = src.fd_r2 = src.fd_r3 = 0;
src.fd_nplanes = c->num_planes;
src.fd_addr = c->sel_data;
dst = src;
dst.fd_stand = 0;
vr_trnfm(x_handle,&src,&dst);
}
}
}
/*
LoadResources : Load a GEM resource file
fname = name of file to load
Return = base pointer of resources or NULL on failure
*/
void *LoadResources(char *fname,short designWidth,short designHeight)
{
OBJECT dummyObj = {-1,-1,-1,G_BOX,0,0,0L,0,0,1,1};
long err;
short handle;
RSHDR hdr;
OBJECT *obj,*tree;
TEDINFO *ti;
ICONBLK *ib;
CICONBLK *cib,**cibh;
BITBLK *bb;
CICON *cicn,*pcicn;
unsigned long osize,size,*index,*addr,*earray;
char *base,*ptext;
short i,j,type,numCibs=0,numRez,*pdata;
rsrc_obfix(&dummyObj,0);
resWidth = dummyObj.ob_width;
resHeight = dummyObj.ob_height;
err = Fopen(fname,O_RDONLY);
if (err<0L)
return NULL;
handle = (short)err;
Fread(handle,sizeof(RSHDR),&hdr);
size = (unsigned long)hdr.rsh_rssize;
osize = (size+1UL)&0xfffffffeUL;
if (hdr.rsh_vrsn&4)
{ /* Extended format, get new 32-bit length */
Fseek(osize,handle,SEEK_SET);
Fread(handle,4L,&size);
}
Fseek(0L,handle,SEEK_SET);
base = (char*)malloc(size+100);
if (!base)
return NULL;
Fread(handle,size,base);
Fclose(handle);
ti = (TEDINFO*)(base+(unsigned long)hdr.rsh_tedinfo);
for (i=0;i<hdr.rsh_nted;i++,ti++)
{ /* Correct all tedinfo field pointers */
ti->te_ptext = (char*)((unsigned long)ti->te_ptext+base);
ti->te_ptmplt = (char*)((unsigned long)ti->te_ptmplt+base);
ti->te_pvalid = (char*)((unsigned long)ti->te_pvalid+base);
}
ib = (ICONBLK*)(base+(unsigned long)hdr.rsh_iconblk);
for (i=0;i<hdr.rsh_nib;i++,ib++)
{ /* Correct all iconblk field pointers */
ib->ib_pmask = (short*)((unsigned long)ib->ib_pmask+base);
ib->ib_pdata = (short*)((unsigned long)ib->ib_pdata+base);
ib->ib_ptext = (char*)((unsigned long)ib->ib_ptext+base);
}
bb = (BITBLK*)(base+(unsigned long)hdr.rsh_bitblk);
for (i=0;i<hdr.rsh_nbb;i++,bb++) /* Correct all bitblk data pointers */
bb->bi_pdata = (short*)((unsigned long)bb->bi_pdata+base);
if (hdr.rsh_vrsn&4)
{ /* It's an enhanced RSC file */
earray = (unsigned long*)(osize+(long)base);
cibh = (CICONBLK**)(earray[1]+(long)base);
if ((long)cibh>0L)
{ /* Get colour icons */
while (*cibh++!=(CICONBLK*)-1L)
numCibs++;
cib = (CICONBLK*)cibh;
cibh = (CICONBLK**)(earray[1]+(long)base);
for (i=0;i<numCibs;i++)
{ /* Fix up all the CICONBLK's */
cibh[i] = cib;
ib = &cib->monoblk;
size = 2UL*(unsigned long)(ib->ib_wicon/16)*(unsigned long)ib->ib_hicon;
addr = (long*)((long)cib+sizeof(ICONBLK));
numRez = (short)*addr;
pdata = (short*)&addr[1];
ib->ib_pdata = pdata;
ib->ib_pmask = (short*)((long)pdata+size);
ptext = (char*)((long)pdata+size*2L);
ib->ib_ptext = ptext;
ptext[11] = 0;
cicn = (CICON*)((long)ptext+12L);
cib->mainlist = cicn;
for (j=0;j<numRez;j++)
{ /* Get CICON's at different rez's */
pcicn = cicn;
pdata = (short*)((long)cicn+sizeof(CICON));
cicn->col_data = pdata;
cicn->col_mask = (short*)((long)pdata+size*(unsigned long)cicn->num_planes);
if (cicn->sel_data!=NULL)
{ /* It's got a selected form */
cicn->sel_data = (short*)((long)cicn->col_mask+size);
cicn->sel_mask = (short*)((long)cicn->sel_data+size*(unsigned long)cicn->num_planes);
cicn = (CICON*)((long)pcicn+sizeof(CICON)+2L*size*((unsigned long)pcicn->num_planes+1L));
}
else
{ /* No selected version */
cicn->sel_data = cicn->sel_mask = NULL;
cicn = (CICON*)((long)pcicn+sizeof(CICON)+size*((unsigned long)pcicn->num_planes+1L));
}
if (pcicn->next_res==(CICON*)1L)
pcicn->next_res = cicn;
else
pcicn->next_res = NULL;
}
cib = (CICONBLK*)cicn;
}
}
}
obj = (OBJECT*)(base+(unsigned long)hdr.rsh_object);
for (i=0;i<hdr.rsh_nobs;i++,obj++)
{ /* Correct all objects' ob_spec pointers */
type = obj->ob_type&255;
switch (type)
{ /* What kind of object is it? */
case G_TEXT:
case G_BOXTEXT:
case G_IMAGE:
case G_BUTTON:
case G_STRING:
case G_FTEXT:
case G_FBOXTEXT:
case G_ICON:
case G_TITLE:
obj->ob_spec = (void*)((unsigned long)obj->ob_spec+base);
break;
case G_CICON:
if ((AESversion<3)||((AESversion==3)&&(AESversion_m<60)))
obj->ob_type=G_ICON;
else
FixColourIconData(cibh[(long)obj->ob_spec]);
obj->ob_spec = cibh[(long)obj->ob_spec];
break;
case G_PROGDEF:
obj->ob_spec = NULL;
break;
case G_IBOX:
case G_BOX:
case G_BOXCHAR:
break;
default:
Cconws("Unknown object type\r\n");
break;
}
}
index = (unsigned long*)(base+(unsigned long)hdr.rsh_trindex);
for (i=0;i<hdr.rsh_ntree;i++,index++)
{
tree = obj = (OBJECT*)(*index+(unsigned long)base);
if ((obj[3].ob_type&255)!=G_TITLE) /* Not a menu tree */
do { /* Fix all object coordinates */
obj->ob_x = (((obj->ob_x&255)*designWidth+(obj->ob_x>>8))*resWidth)/designWidth;
obj->ob_y = (((obj->ob_y&255)*designHeight+(obj->ob_y>>8))*resHeight)/designHeight;
obj->ob_width = (((obj->ob_width&255)*designWidth+(obj->ob_width>>8))*resWidth)/designWidth;
obj->ob_height = (((obj->ob_height&255)*designHeight+(obj->ob_height>>8))*resHeight)/designHeight;
} while (!(obj++->ob_flags&LASTOB));
else
{ /* Standard AES menu */
j = 0;
do { /* Use conventional AES routine */
rsrc_obfix(tree,j);
} while (!(tree[j++].ob_flags&LASTOB));
}
}
return (void*)base;
}
/*
FreeResources : Dispose of a set of loaded resources
base = pointer to base of resources
*/
void FreeResources(void *base)
{
free(base);
}
/*
ResourceTree : Find the tree with a given index
base = pointer to base of resources
num = index number of tree
Return = pointer to tree or NULL on failure
*/
OBJECT *ResourceTree(void *base,short num)
{
unsigned long *index,offset;
RSHDR *hdr = (RSHDR*)base;
if ((!hdr)||(num<0)||(num>=hdr->rsh_ntree))
return NULL;
index = (unsigned long*)((unsigned long)base+(unsigned long)hdr->rsh_trindex);
offset = index[num];
return (OBJECT*)((unsigned long)base+offset);
}
/* ResourceString : Find the string with a given index
base = pointer to base of resources
num = index number of string
Return = pointer to string or NULL on failure
*/
char *ResourceString(void *base,short num)
{
unsigned long *index,offset;
RSHDR *hdr = (RSHDR*)base;
if (!(hdr)||(num<0)||(num>=hdr->rsh_nstring))
return(NULL);
index = (unsigned long*)((unsigned long)base+(unsigned long)hdr->rsh_frstr);
offset = index[num];
return((char*)((unsigned long)base+offset));
}
/*
ResourceImage : Find the image with a given index
base = pointer to base of resources
num = index number of image
Return = pointer to image or NULL on failure
*/
void *ResourceImage(void *base,short num)
{
unsigned long *index,offset;
RSHDR *hdr = (RSHDR*)base;
if ((!hdr)||(num<0)||(num>=hdr->rsh_nimages))
return(NULL);
index = (unsigned long*)((unsigned long)base+(unsigned long)hdr->rsh_frimg);
offset = index[num];
return((void*)((unsigned long)base+offset));
}